package com.aipartner.mapper;

import com.aipartner.entity.UserWork;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户作品Mapper
 * 
 * @author AI Partner Team
 * @since 2024-09-14
 */
@Mapper
public interface UserWorkMapper extends BaseMapper<UserWork> {

    /**
     * 根据用户ID获取用户作品列表
     */
    @Select("SELECT * FROM user_works WHERE user_id = #{userId} AND status = 1 ORDER BY create_time DESC")
    List<UserWork> selectByUserId(Long userId);

    /**
     * 获取公开的用户作品列表
     */
    @Select("SELECT * FROM user_works WHERE status = 1 AND is_public = 1 ORDER BY create_time DESC LIMIT #{offset}, #{limit}")
    List<UserWork> selectPublicWorks(int offset, int limit);

    /**
     * 增加查看次数
     */
    @Update("UPDATE user_works SET view_count = view_count + 1 WHERE id = #{id}")
    int incrementViewCount(Long id);

    /**
     * 更新点赞数
     */
    @Update("UPDATE user_works SET like_count = #{likeCount} WHERE id = #{id}")
    int updateLikeCount(Long id, Integer likeCount);

    /**
     * 更新评论数
     */
    @Update("UPDATE user_works SET comment_count = comment_count + #{increment} WHERE id = #{id}")
    int updateCommentCount(Long id, Integer increment);
}
